import 'package:flutter/material.dart';
import 'package:moose_app/core/model/follow_item_model.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/common/common_comment_item.dart';
import 'package:moose_app/ui/widgets/operator_view.dart';
import 'package:moose_app/ui/widgets/user/user_avatar.dart';

class ATHFollowItem extends StatelessWidget {
  final ATHFollowItemModel followItem;

  const ATHFollowItem({Key key, this.followItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          ATHFollowUserInfo(followItem: followItem),
          ATHFollowContent(followItem: followItem),
          followItem.images.length > 0
              ? ATHFollowGridImage(followItem: followItem)
              : SizedBox(),
          ATHCommonCommentItem(),
          ATHFollowOperation(followItem: followItem),
          Padding(
            padding: EdgeInsets.symmetric(vertical: kSize20),
            child: Divider(),
          ),
        ],
      ),
    );
  }
}

class ATHFollowOperation extends StatelessWidget {
  final ATHFollowItemModel followItem;

  const ATHFollowOperation({Key key, this.followItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(top: kSize20),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
              padding:
                  EdgeInsets.symmetric(horizontal: kSize10, vertical: kSize4),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(kSize8)),
                  shape: BoxShape.rectangle,
                  color: kColorF1),
              child: Text(
                followItem.tag ?? "",
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(fontSize: kSize24, color: kColor99),
              )),
          Padding(
            padding: EdgeInsets.only(top: kSize16),
            child: ATHOperatorView(),
          ),
        ],
      ),
    );
  }
}

class ATHFollowGridImage extends StatelessWidget {
  final ATHFollowItemModel followItem;

  const ATHFollowGridImage({Key key, this.followItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<String> imageList = followItem.images;
    return GridView.custom(
      shrinkWrap: true,
      padding: EdgeInsets.only(top: kSize20),
      physics: NeverScrollableScrollPhysics(),
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
        mainAxisSpacing: kSize20,
        crossAxisSpacing: kSize20,
      ),
      childrenDelegate: SliverChildBuilderDelegate((context, position) {
        String imagePath = imageList[position];
        return Container(
          child: ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(kSize8)),
            child: Image.asset(
              imagePath,
              fit: BoxFit.cover,
            ),
          ),
        );
      }, childCount: imageList.length),
    );
  }
}

class ATHFollowContent extends StatelessWidget {
  final ATHFollowItemModel followItem;

  const ATHFollowContent({Key key, this.followItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Padding(
          padding: EdgeInsets.symmetric(vertical: kSize20),
          child: Text(
            followItem.poetryItem.poetryTitle ?? "",
            style: TextStyle(color: kColor33, fontSize: kFontSize36),
          ),
        ),
        Text(followItem.poetryItem.poetryContent ?? "",
            style: TextStyle(color: kColor33, fontSize: kFontSize32))
      ],
    );
  }
}

class ATHFollowUserInfo extends StatelessWidget {
  final ATHFollowItemModel followItem;

  const ATHFollowUserInfo({Key key, this.followItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Container(
          child: ATHUserAvatar(
            avatarPath: followItem.poetryItem.poetryAvatar,
          ),
        ),
        Expanded(
          child: Container(
            padding: EdgeInsets.only(left: kSize24),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    Text(
                      followItem.poetryItem.poetryAuthor ?? "",
                      style: TextStyle(color: kColor33, fontSize: kFontSize30),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: <Widget>[
                    Text(
                      followItem.createTime ?? "",
                      style: TextStyle(color: kColor33),
                    ),
                  ],
                )
              ],
            ),
          ),
        )
      ],
    );
  }
}
